<div class="row"> <h3 class="page-header">节点管理</h3></div>
<div class="row">
    <div class="panel panel-default">
        <div class="panel-body">
            <label><a class="btn btn-primary addText" data-id='{$list.id}'>添加节点</a></label>
            <div class="table-responsive">
                <table class="table table-striped table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>节点名称</th>
                            <th>节点路径</th>
                            <th width="75">排序</th>
                            <th width="75">状态</th>
                            <th width="120">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <volist name="list" id="list_node">
                            <tr>
                                <switch name='list_node.num'>
                                    <case value='3'><assign name='str' value='&nbsp;|&nbsp;&nbsp;|&nbsp;&nbsp;|-&nbsp;'/></case>
                                    <case value='2'><assign name='str' value='&nbsp;|&nbsp;&nbsp;|-&nbsp;'/></case>
                                    <default/><assign name='str' value='&nbsp;|-&nbsp;'/>
                                </switch>
                                <td>{$str}{$list_node.title}</td>
                                <td>{$str}{$list_node.name}</td>
                                <td><input class="setSort" type="text" size="5" data-url="{:U('Node/setSort?id='.$list_node['id'])}" value="{$list_node.sort}"></td>
                                <td>
                                    <button class='btn <eq name="list_node.status" value="1">btn-primary<else />btn-default</eq> btn-sm setStatus' type="button" data-url='{:U("Node/setStatus?id=".$list_node["id"])}' data-status="{$list_node.status}"><eq name="list_node.status" value='1'>启用<else />禁用</eq></button>
                                </td>
                                <td>
                                    <a class="btn-sm btn btn-default editText" data-id='{$list_node.id}'>修改</a>
                                    <button data-url='{:U("Node/del?id=".$list_node["id"])}' class="btn-sm btn btn-default delBtn" type="button">删除</button>
                                </td>
                            </tr>
                        </volist>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<div id="myModal" class="modal fade in" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="{:U('Node/add')}" id="myform" class="form-horizontal">
            <div class="modal-header">
                    <button data-dismiss="modal" class="close" type="button">×</button>
                    <h4 class="modal-title">分类管理</h4>
                </div>
                 <div class="modal-body">
                <div class="form-group">
                    <label class="col-sm-3 control-label">父节点：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                        <select class="form-control" id="pid" name="pid">
                            <option value="0" >无上级节点</option>
                            <volist name='list' id='node'>
                                <lt name='node.num' value='3'>
                                    <option value="{$node.id}"<eq name='node.id' value='$info.pid'> selected </eq> ><eq name="node.pid" value="0">|-<else/>|&nbsp;|-</eq>{$node.title}</option>
                                </lt>
                            </volist>
                        </select>           
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">节点名称：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control required" name="title" value="{$info.title}" maxlength='10'>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">节点路径：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control required" name="name" value="{$info.name}" maxlength='40'>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">排序：</label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control digits" name="set_sort" value="100">
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">状态：</label>
                    <div class="col-sm-4 input-group">
                        <label class="radio-inline">
                            <input type="radio" value="1" name="set_status" checked>启用
                        </label>
                        <label class="radio-inline">
                            <input type="radio" value="0" name="set_status">禁用<BR>
                        </label>
                    </div>
                </div>
                </div>
                <div class="modal-footer">
                    <button data-dismiss="modal" class=" btn btn-default" type="button">关闭</button>
                    <button class="btn btn-primary" type="submit">保存</button>
                </div>
                <input type='hidden' name='id' value='{$info.id}'>
            </form>
        </div>
    </div>
</div>


<script type="text/javascript">
    $(function(){
        $('.open').click(function(){
            if($(this).data('open') == 0){
                $(this).removeClass('fa-minus').addClass('fa-plus');
                $('.level'+$(this).data('id')).addClass('hide');
            }else{
                $(this).removeClass('fa-plus').addClass('fa-minus');
                $('.level'+$(this).data('id')).removeClass('hide');
            }
            $(this).data('open', $(this).data('open') == 1 ? 0 : 1);
        });
    })

    $(function(){
    $('.addClassify').click(function(){
        $('#myform')[0].reset();
        $('#myModal').modal('show');
    });
    $('.addText').click(function(){
        $('#myModal').modal('show');
    });

    $('.editText').click(function(){
        $('#myform')[0].reset();
        var id = $(this).data('id'); waiting();
        $.get('{:U("Node/edit")}', {id: id}, function(data){
            complete();
            if(data.status == 1){
                var _get_info = data.info;
                $('#myform input[name="id"]').val(_get_info.id);
                $('#myform input[name="title"]').val(_get_info.title);
                $('#myform input[name="name"]').val(_get_info.name);
                $('#myform select[name="pid"]').val(_get_info.pid);
                $('#myform input[name="set_sort"]').val(_get_info.sort); 
                $("#myform :radio[name=set_status][value='"+_get_info.status+"']").attr("checked",true)
                $('#myform').attr('action', '{:U("Node/edit")}');
                $('#myModal').modal('show');
            }else{
                showInfo(data.info);
                //setTimeout('_form_defult_callback()', 1600);
            }
        });
        
    });
})

</script>